﻿

CKEDITOR.plugins.add( 'savebtn', {
    icons: 'savebtn',
    init: function( editor ) {
        editor.addCommand( 'savecontent', {
        	modes : { wysiwyg:1, source:1 },
        	exec : function(editor){
	        		editor.updateElement();
	        		loading_icon=CKEDITOR.basePath+'plugins/savebtn/icons/loader.gif';
              normal_icon=$('.cke_button__savebtn_icon').css('background-image');
              $('.cke_button__savebtn_icon').css("background-image", "url("+loading_icon+")");
              editor.updateElement();
        			$.post(MANAGER_SERVLET, {
        				command : "saveFile",
        				file : fileName,
        				directory : dir,
        				fileContent : editor.getData()
        			}, function(data) {
        				if (data == null || data['success'] != true) {
        					jAlert('error', data.msg);
        					return;
        				}
        				$('.cke_button__savebtn_icon').css("background-image", normal_icon);
        				jAlert("info","保存成功","提示");
        			}, "json");
        	} 
    });


//add the save button to the toolbar

        editor.ui.addButton( 'savebtn', {
            label: '保存',
            command: 'savecontent'
           // toolbar: 'insert'
        });


    }
});